<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: yangweijie <yangweijiester@gmail.com> <code-tech.diandian.com>
// +----------------------------------------------------------------------

namespace App\Controller;
use Think\Controller;
use OT;
use User\Api\UserApi;

//学生
class StudentController extends AppController{
   
   public function login($username,$password){
       $map['name']      =  $username;
       $map['password']  =  $password;
       $student = M('Student');
       $rst = $student->where($map)->find();
       if($rst){
           $data['success'] = true;
           $data['msg']     = '登陆成功';
           $data['obj']     = $rst;
       }else{
           $data['success'] = false;
           $data['msg']     = '登陆失败';
       }
       $this->ajaxReturn($data,'JSON');

   }
    //得到当前学生列表
    public function getList(){
        $student = D('Student');
        $rst = $student->select();
       //$map['status']  = 1;
        //$rst = $this->lists('Student',$map);
        if($rst){
            $data['success']  = true;
            $data['msg']      = '获取成功';
            $data['rows']     = $rst;

        }else{
            $data['success'] = false;
            $data['msg']     = '获取失败';
        }
        $this->ajaxReturn($data,'JSON');
    }
    public function getImageList(){
        $student = D('Student');
        $rst = $student->select();
        //$map['status']  = 1;
        //$rst = $this->lists('Student',$map);
        if($rst){
            $data['success']  = true;
            $data['msg']      = '获取成功';
            $data['rows']     = $rst;

        }else{
            $data['success'] = false;
            $data['msg']     = '获取失败';
        }
        $this->ajaxReturn($data,'JSON');
    }
    //分页
    //http://document.thinkphp.cn/manual_3_2.html#data_page
    //$curPage当前页码
    //$pageSize每页显示的数目
    public function getPageList($curPage,$pageSize){
        $student = D('Student');
        $data['page']['totalRows'] = $student->count();
        $data['page']['totalPage'] = $data['page']['totalRows']/$pageSize;
        $data['page']['curPage']   = $curPage;
        $data['page']['pageSize']  = $pageSize;
        //$Page       = new \Think\Page($count,10);
        //$show       = $Page->show();// 分页显示输出
        //$list = $User->where('status=1')->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();
        $rst = $student->limit(($curPage*$pageSize-$pageSize).','.$pageSize)->select();
        //$map['status']  = 1;
        //$rst = $this->lists('Student',$map);
        if($rst){
            $data['success']  = true;
            $data['msg']      = '获取成功';
            $data['rows']     = $rst;
            //$data['page']     = $Page;
        }else{
            $data['success'] = false;
            $data['msg']     = '获取失败';
        }
        $this->ajaxReturn($data,'JSON');
    }
}